#include <iostream>
#include <signal.h>
#include <unistd.h>

using namespace std;

int flag = 0;
void changeFlag(int signum)
{
    (void)signum;
    cout << "changeFlag: " << flag;
    flag = 1;
    cout << "->" << flag << endl;
}

int main()
{
    signal(2, changeFlag);
    while (!flag);
    cout << "after normal process quit: " << flag << endl;
}
/*
[hbr@VM-16-9-centos catch]$ ./mysignal 
^CchangeFlag: 0->1
after normal process quit: 1
*/